package logic

import (
	"context"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"user_srv/model"
	"user_srv/user_proto"
)

func (s *Server) BookList(ctx context.Context, in *user_proto.BookListRequest) (*user_proto.BookListResponse, error) {
	list, err := model.BookList(in.Name, int(in.Page), int(in.Limit))
	if err != nil {
		return nil, status.Errorf(codes.Internal, "查询漫画失败")
	}
	var bookList []*user_proto.BookInfo
	for _, v := range list {
		bookList = append(bookList, &user_proto.BookInfo{
			Id:      int64(v.ID),
			Name:    v.Name,
			Content: v.Content,
			Types:   v.Types,
			Author:  v.Author,
			Hot:     int64(v.Hot),
		})
	}
	return &user_proto.BookListResponse{BookInfo: bookList}, nil
}
